﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MidExam.DAL.Models;
using Leafing.Data;

public partial class Youyong_Shenhe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            BindData();
    }

    private void BindData()
    {
        this.lblTot.Text = string.Format("总人数{0}已核对{1}未完成{2}"
            ,Youyong.GetCount(Condition.Empty)
            , Youyong.GetCount(p => p.InputCheck == true)
            , Youyong.GetCount(p => p.InputCheck != true)
            );
        //this.GridView1.DataSource = Youyong.Find(p=>p.InputCheck !=true,"bmxh");
        //this.GridView1.DataBind();
        this.RefreshViewer(0);
    }

    private void RefreshViewer(int NewIndex)
    {
        //IPagedSelector<Youyong> ps = DbEntry
        //    .From<Youyong>()
        //    .Where(p=>p.InputCheck==false)
        //    .OrderBy("bmxh")
        //    .PageSize(GridView1.PageSize)
        //    .GetPagedSelector();

        //var count = ps.GetResultCount();
        //var list = ps.GetCurrentPage(this.GridView1.PageIndex);

        GridView1.PageIndex = NewIndex;
        if(this.DropDownList1.SelectedIndex == 0)
            this.GridView1.DataSource = Youyong.Find(Condition.Empty, "Bmxh");
        else if(this.DropDownList1.SelectedValue == "未录入")
            GridView1.DataSource = Youyong.Find(p=>p.InputCheck !=true,"Bmxh");
        else
            GridView1.DataSource = Youyong.Find(p => p.InputCheck == true, "Bmxh");
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.RefreshViewer(e.NewPageIndex);
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.RefreshViewer(0);
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string bmxh = e.CommandArgument.ToString();
        Youyong youyong = Youyong.FindOne(p => p.bmxh == bmxh);
        if (youyong != null)
        {
            youyong.InputCheck = false;
            youyong.Save();
        }
        this.BindData();
    }
}